#ifndef _COBSERVER_H_
#define _COBSERVER_H_

class IObserver
{
public:
	virtual void handleEvent(int _cursor, int _dx, int _dy) = 0;
};

class Observable
{
private:
	std::map<IObserver* const, IObserver* const > _observers;
	typedef std::map<IObserver* const, IObserver* const >::value_type item;

protected:
	void notify(int _cursor, int _dx, int _dy)
	{
		for (std::map<IObserver* const, IObserver* const >::iterator it =
				_observers.begin(); it != _observers.end(); ++it)
		{
			it->second->handleEvent(_cursor, _dx, _dy);
		}
	}

public:
	void add(IObserver& ref)
	{
		_observers.insert(item(&ref, &ref));
	}

	void remove(IObserver& ref)
	{
		_observers.erase(&ref);
	}
};

#endif
